'use strict'

const pg =require('pg');

let psql = new pg.Pool({//这是异步的
    host:'127.0.0.1',
    port:5432,
    user:'zzl',
    password :'123456789',
    database:'zzl',
    // 最大客户端连接数量
    max:8
})

;(async () => {//这里加分号是为了防止被编译器误认为是函数调用
    let sqltext = `insert into`
                    +` content(id, title, detail, add_time, update_time)`
                    +`values($1,$2,$3,$4,$5)`//$1,$2...对应上面五个变量
    let tm = Date.now();
    let ret = await psql.query(sqltext, [
        `${tm}`,
        `${Math.random()}`,
        '测试内容',
        tm,
        tm
    ])

    let ret2 = await psql.query(`select * from content`);
    
    psql.end();
    
    console.log(ret,ret2);
})();